import echarts from 'echarts';
import { parse } from 'utils/';
export default {
    name: 'home',
    data() {
        return {
            chartColumn: null,
            chartBar: null,
            chartLine: null,
            chartPie: null
        }
    },
    mounted: function () {
        var _this = this;
        //基于准备好的dom，初始化echarts实例
        this.chartColumn = echarts.init(document.getElementById('chartColumn'));
        this.chartBar = echarts.init(document.getElementById('chartBar'));
        this.chartLine = echarts.init(document.getElementById('chartLine'));
        this.chartPie = echarts.init(document.getElementById('chartPie'));

        this.chartColumn.setOption({
            title: {
                text: 'Column Chart'
            },
            tooltip: {},
            xAxis: {
                data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }]
        });

        this.chartBar.setOption({
            title: {
                text: 'bar Chart',
                subtext: '数据来自网络'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            legend: {
                data: ['2011年', '2012年']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type: 'value',
                boundaryGap: [0, 0.01]
            },
            yAxis: {
                type: 'category',
                data: ['巴西', '印尼', '美国', '印度', '中国', '世界人口(万)']
            },
            series: [{
                name: '2011年',
                type: 'bar',
                data: [18203, 23489, 29034, 104970, 131744, 630230]
            }, {
                name: '2012年',
                type: 'bar',
                data: [19325, 23438, 31000, 121594, 134141, 681807]
            }]
        });

        this.chartLine.setOption({
            title: {
                text: 'line Chart'
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['邮件营销', '联盟广告', '搜索引擎']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
            },
            yAxis: {
                type: 'value'
            },
            series: [{
                name: '邮件营销',
                type: 'line',
                stack: '总量',
                data: [120, 132, 101, 134, 90, 230, 210]
            }, {
                name: '联盟广告',
                type: 'line',
                stack: '总量',
                data: [220, 182, 191, 234, 290, 330, 310]
            }, {
                name: '搜索引擎',
                type: 'line',
                stack: '总量',
                data: [820, 932, 901, 934, 1290, 1330, 1320]
            }]
        });

        this.chartPie.setOption({
            title: {
                text: 'pie Chart',
                subtext: '纯属虚构',
                x: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                left: 'left',
                data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
            },
            series: [{
                name: '访问来源',
                type: 'pie',
                radius: '55%',
                center: ['50%', '60%'],
                data: [{
                    value: 335,
                    name: '直接访问'
                }, {
                    value: 310,
                    name: '邮件营销'
                }, {
                    value: 234,
                    name: '联盟广告'
                }, {
                    value: 135,
                    name: '视频广告'
                }, {
                    value: 1548,
                    name: '搜索引擎'
                }],
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }]
        });
    },
    methods: {
        initData: () => {
            console.log('initData', parse);
            // parse.create('UserCoupon', {
            //     userId: 'unknown',
            //     nickname: 'unknown',
            //     couponId: 'NyQ26OE1SF',
            //     couponName: '1元券',
            //     isUsed: 0,
            //     useTime: '',
            //     endTime: '2017-10-20',
            //     orderId: 'unknown',
            //     orderName: 'unknown'
            // }).subscribe(next => { }, err => { });

            // parse.create('UserShippingAddress', {
            //     name: '幻影沙漏',
            //     mobile: '18005710923',
            //     province: '浙江省',
            //     city: '杭州市',
            //     area: '余杭区',
            //     address: '绿叮小区',
            //     tag: 1,
            //     isDefault: 1,
            //     userId: 'unknown',
            //     nickname: '幻影沙漏'
            // }).subscribe(next => { }, err => { });

            // parse.create('WxUser', {
            //     nickname: '幻影沙漏',
            //     gender: 1,
            //     birthday: '2000-16-26',
            //     mobile: '18005710923',
            //     avatar: 'http://120.55.49.187/parse/files/app-good-goods/d37e4f8901f679062d29c0afcd82a34b_20160428090412IMG_1256.JPG',
            //     weixinOpenId: '123456465787',
            //     isSelecter: 0,
            //     status: 0,
            //     isConsumer: 1,
            //     recommendSerialNum: '',
            //     lastLoginTime: ''
            // }).subscribe(next => { }, err => { });

            // parse.create('Finder', {
            //     nickname: '幻影沙漏',
            //     name: 'chenchen',
            //     gender: 1,
            //     mobile: '18005710923',
            //     avatar: 'http://120.55.49.187/parse/files/app-good-goods/d37e4f8901f679062d29c0afcd82a34b_20160428090412IMG_1256.JPG',
            //     identityCard: '123456465787',
            //     address: '浙江省杭州市',
            //     desc: '大家好，我是有好东西的寻味师宝柱。我以前是一名军人，在中南海保护国家领导人。退伍后，我加入了沃尔玛做果蔬主管。随着对这个行业的深入了解，我越来越喜欢生鲜行业了。我希望，我能以军人的严苛要求，把全世界的好东西带给大家。',
            //     content: '无',
            //     title: '为你寻找世界各地的好水果'
            // }, 'serialNum').subscribe(next => { }, err => { });

            // parse.create('OriginStory', {
            //     finderId: 'v4eNczsqpB',
            //     finderName: '幻影沙漏',
            //     goodsName: '金华火腿',
            //     content: '无',
            //     listPicUrl: 'http://120.55.49.187/parse/files/app-good-goods/d37e4f8901f679062d29c0afcd82a34b_20160428090412IMG_1256.JPG,http://120.55.49.187/parse/files/app-good-goods/d37e4f8901f679062d29c0afcd82a34b_20160428090412IMG_1256.JPG',
            //     status: true
            // }).subscribe(next => { }, err => { });

            // parse.create('Selecter', {
            //     nickname: '幻影沙漏',
            //     mobile: '18022559999',
            //     status: 1,
            //     feedback: '',
            //     userId: '',
            //     totalDeduct: 100.29,
            //     serialNum: 1,
            //     withdrawAmount: 60.29,
            //     noWithdrawAmount: 40,
            //     profession: '程序员',
            //     community: '自定义社区',
            //     recommendSerialNum: 1,
            //     isGroupOwner: true,
            //     isSeller: false,
            //     from: '微信',
            //     desc: 'hello world',
            //     gender: 1,
            //     name: 'hello world',
            //     province: '浙江省',
            //     city: '杭州市',
            //     area: '余杭区'
            // }).subscribe(next => { }, err => { });

            // parse.create('GoodsComment', {
            //     content: '商品不错，鲜嫩多汁',
            //     listPicUrl: 'http://120.55.49.187/parse/files/app-good-goods/d37e4f8901f679062d29c0afcd82a34b_20160428090412IMG_1256.JPG,http://120.55.49.187/parse/files/app-good-goods/d37e4f8901f679062d29c0afcd82a34b_20160428090412IMG_1256.JPG',
            //     status: 1,
            //     isReverted: 0,
            //     feedback: '',
            //     likecount: 100,
            //     userId: 'plPIdKoWBT',
            //     userName: 'anonymous',
            //     goodsId: 'Ujgt7A5wb0',
            //     goodsName: '广式&传统速食早点系列 |多种口味随心选，优质选材，健康美味 (Frozen Dim Sum&Chinese Pastries)',
            //     orderId: '3ZBK8IHDTd',
            // }).subscribe(next => { }, err => { });

            // parse.create('FinderDeductSum', {
            //     finderId: 'eYlknOXOCu',
            //     finderName: '幻影沙漏',
            //     price: 36.33,
            //     startTime: '2017-10-22',
            //     endTime: '2017-10-30',
            //     payStatus: false,
            //     payTime: '',
            //     nickname: '幻影沙漏',
            //     mobile: '1855366666',
            //     orderId: 'EIbjZEUFfq'
            // }).subscribe(next => { }, err => { });

            // parse.create('FinderDeductDetail', {
            //     finderId: 'eYlknOXOCu',
            //     finderName: '幻影沙漏',
            //     orderId: 'EIbjZEUFfq',
            //     salePrice: 568,
            //     deduct: 36.33,
            //     nickname: '幻影沙漏',
            //     mobile: '1855366666',
            //     scale: '4',
            //     payStatus: false,
            //     payTime: ''
            // }).subscribe(next => { }, err => { });

            // parse.create('SelecterDeductDetail', {
            //     selecterId: 'NHSyj2oMwr',
            //     selecterName: 'hello world',
            //     nickname: '幻影沙漏',
            //     mobile: '18566669999',
            //     orderId: 'EIbjZEUFfq',
            //     salePrice: 568,
            //     deduct: 36.33,
            // }).subscribe(next => { }, err => { });

            // parse.create('SelecterWithdraw', {
            //     selecterId: 'NHSyj2oMwr',
            //     selecterName: 'hello world',
            //     serialNum: 1,
            //     nickname: '幻影沙漏',
            //     mobile: '18566669999',
            //     orderId: 'EIbjZEUFfq',
            //     price: 568,
            //     payStatus: false,
            //     payTime: ''
            // }).subscribe(next => { }, err => { });

            let addrs = []
            let pop = ["310100", "110100", "120100", "500100"];
            parse.query('Region', query => query.equalTo('level', 1))
                .filter(x => x.type && x.type === 'result')
                .map(x => x.result)
                .subscribe(next => {
                    next.forEach((item, i) => {
                        parse.query('Region', query => query.equalTo('parentCode', item.attributes.code))
                            .filter(x => x.type && x.type === 'result')
                            .map(x => x.result)
                            .subscribe(next2 => {
                                if (pop.indexOf(item.attributes.code) != -1) {
                                    addrs.push({
                                        code: item.attributes.code,
                                        name: item.attributes.name,
                                        children: next2.map(v => { return { code: v.attributes.code, name: v.attributes.name} })
                                    })
                                } else {
                                    addrs.push({
                                        code: item.attributes.code,
                                        name: item.attributes.name,
                                        children: []
                                    })
                                    next2.forEach((item2, i2) => {
                                        parse.query('Region', query => query.equalTo('parentCode', item2.attributes.code))
                                            .filter(x => x.type && x.type === 'result')
                                            .map(x => x.result)
                                            .subscribe(next3 => {
                                                addrs[i].children.push({
                                                    code: item2.attributes.code,
                                                    name: item2.attributes.name,
                                                    children: next3.map(v => { return { code: v.attributes.code, name: v.attributes.name } })
                                                })
                                            });
                                    })
                                }
                            });
                    })
                });
            
            setTimeout(() => {
                console.log('addr:', JSON.stringify(addrs));
            },20000)
        }
    }
}